var mf=null;
var lastVisitA=null;
var upMenu=null;
var imgCollapse=_TMPL_+"../Admin/Public/img/collapsed.gif";
var imgExpand=_TMPL_+"../Admin/Public/img/expanded.gif";
var win=null;
var yabody=null;
var hiddenLink=null;
var basePageTitle=null;
var yaModal=null;

$(function(){
    mf=$("#mainFrame");
    $("#menu .collapse").click(function(){
        var $this=$(this);
        if($this.is(".expand")){  //如果是展开状态，则收缩当前项
            $this.next("ul:first").slideUp("",function(){ $this.removeClass().addClass("collapse"); });
            $("img",$this).attr("src",imgCollapse);
        }else{  //展开当前项
            if(upMenu) upMenu.removeClass("up");
            $this.removeClass().addClass("expand");
            $this.next("ul:first").slideDown();
            $("img",$this).attr("src",imgExpand);
            //下一级的样式要改变下
            upMenu=$this.parent("li").next().children("a");
            upMenu.addClass("up");
        }
    });
    $("#menu .secMenu a").click(function(e,href){
        var $a=$(this);
        $a.blur();
        if(!href) href=$a.attr("href");
        if(lastVisitA && lastVisitA==$a) return;
        if(lastVisitA) lastVisitA.removeClass("current");
        $a.removeClass("hover").addClass("current");
        lastVisitA=$a;
    }).hover(
        function(){
            var $a=$(this);
            if(!$a.is(".current")) $a.addClass("hover");
        },
        function(){
            $(this).removeClass("hover");
        }
    ).attr("target","mainFrame");
    win=$(window);
    yabody=$("#yabody");
    adjustPage();
    win.bind("resize",function(){adjustPage();});
    yaModal=new modal();
    if(typeof(_goLink)!="undefined"){
        document.cookie="goLink=;path="+_APP_+";expires=05 Jan 2008 00:00:00 GMT";
        mf.attr("src",_goLink);
    }
});

//同步链接，使iframe内的页面和菜单相对应
function synchMenu(strUrl){
    var arr=strUrl.split(_APP_);
    strUrl=arr[1].substr(1).split(/\/|\\/);
    var goLink=strUrl[0]+"_"+strUrl[1];
    var aLinker=$("#"+goLink);
    if(aLinker.size()==0){
        aLinker=$("#"+strUrl[0]+"_index");
    }
    if(aLinker.size()>0){
        var parentA=aLinker.parents("li:eq(1)").children("a:first");
        if(parentA.is(".collapse")){ parentA.click(); }
        aLinker.click();
    }
}

//调整界面的宽高等
function adjustPage(){
    yabody.height(win.height()-50);
}

//注册界面上的搜索
var yaSearch={};
yaSearch.init=function(searchForm,inputText,searchBtn,advancedBtn){
    this.form=searchForm;
    this.input=inputText;
    this.search=searchBtn;
    this.advanced=advancedBtn;
    this.inputOriginBackgroundColor=this.input.css("background-color");
    this.inputOriginColor=this.input.css("color");
    this.input.focus(function(){yaSearch.getFocus();});
    this.input.blur(function(){yaSearch.lostFocus();});
    this.search.click(function(){   //执行搜索

    });
}
/** options的参数
  .action   表单提交位置,必需
  .name     表单中文本框的name属性,默认值为name
  .tip      输入框中的原始值，默认值为"搜索..."
  .advanced 高级搜索时调用的URL，将在模拟模式对话框中打开此地址。如果没有此项，将使高级搜索不可用
 */
yaSearch.register=function(options){
    this.inputOriginValue=( "tip" in options )?options.tip:"搜索...";
    this.input.val(this.inputOriginValue);
    this.form.attr("action",options.action);
    this.input.attr("name",("name" in options)?options.name:"name");
    if("advanced" in options){
        this.advanced.attr("disabled",false).removeClass("disabled");
        this.advanced.click(function(){
                yaModal.html(options.advanced);
                });
    }else{
        this.advanced.attr("disabled",true).addClass("disabled");
    }
}
//搜索框获取到焦点后的效果
yaSearch.getFocus=function(){
    if($.trim(this.input.val())==this.inputOriginValue){
        this.input.val("");
    }
    this.input.css({"background-color":"#fff","color":"#187A2C"});
}
//失去焦点
yaSearch.lostFocus=function(){
    if($.trim(this.input.val())==""){
        this.input.val(this.inputOriginValue);
    }
    this.input.css({"background-color":this.inputOriginBackgroundColor,"color":this.inputOriginColor});
}
